package com.parleys.activity;

import roboguice.activity.GuiceActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

import com.parleys.R;
import com.parleys.domain.Channel;
import com.parleys.domain.Presentation;
import com.parleys.domain.Space;
import com.parleys.helper.ApplicationConstants;

public abstract class AbstractParleysActivity extends GuiceActivity {

	private boolean customTitleEnabled = true;

	@Override
	public void setTitle(CharSequence title) {
		super.setTitle(title);
		if (customTitleEnabled) {
			((TextView) findViewById(R.id.title)).setText(title);
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		if (customTitleEnabled) {
			getWindow().requestFeature(Window.FEATURE_CUSTOM_TITLE);
		}
		super.onCreate(savedInstanceState);
	}

	@Override
	public void setContentView(View view) {
		super.setContentView(view);
		if (customTitleEnabled) {
			getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
		}
	}

	@Override
	public void setContentView(int layoutResID) {
		super.setContentView(layoutResID);
		if (customTitleEnabled) {
			getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
		}
	}

	@Override
	public void setContentView(View view, LayoutParams params) {
		super.setContentView(view, params);
		if (customTitleEnabled) {
			getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
		}
	}

	public boolean isCustomTitleEnabled() {
		return customTitleEnabled;
	}

	public void setCustomTitleEnabled(boolean customTitleEnabled) {
		this.customTitleEnabled = customTitleEnabled;
	}

	protected void gotoDetailActivity(final Space space, final Channel channel, final Presentation presentation,
			final Boolean online) {
		Intent intent = new Intent(this, PresentationDetailActivity.class);
		intent.putExtra(ApplicationConstants.SPACE_ARG, space);
		intent.putExtra(ApplicationConstants.CHANNEL_ARG, channel);
		intent.putExtra(ApplicationConstants.PRESENTATION_ARG, presentation);
		intent.putExtra(ApplicationConstants.ONLINE_ARG, online);
		startActivity(intent);
	}

	protected void gotoSlidesActivity(final Space space, final Channel channel, final Presentation presentation,
			final Boolean online) {
		Intent intent = new Intent(this, GalleryActivity.class);
		intent.putExtra(ApplicationConstants.SPACE_ARG, space);
		intent.putExtra(ApplicationConstants.CHANNEL_ARG, channel);
		intent.putExtra(ApplicationConstants.PRESENTATION_ARG, presentation);
		intent.putExtra(ApplicationConstants.ONLINE_ARG, online);
		startActivity(intent);
	}

	protected void gotoChaptersActivity(final Space space, final Channel channel, final Presentation presentation,
			final Boolean online) {
		Intent intent = new Intent(this, ChapterListActivity.class);
		intent.putExtra(ApplicationConstants.SPACE_ARG, space);
		intent.putExtra(ApplicationConstants.CHANNEL_ARG, channel);
		intent.putExtra(ApplicationConstants.PRESENTATION_ARG, presentation);
		intent.putExtra(ApplicationConstants.ONLINE_ARG, online);
		startActivity(intent);
	}

}
